package org.metasketch.demo.editor;

import org.metasketch.editor.Editor;
import org.metasketch.editor.IProjectHandler;
import org.metasketch.editor.debug.JFXPrintTextArea;
import org.metasketch.editor.project.MultipleProjectHandler;
import org.metasketch.editor.timeline.SnapshotManager;
import org.metasketch.editor.toolbox.GenericTools;
import org.metasketch.editor.toolbox.PerspectiveChooser;
import org.metasketch.file.FileHandler;
import org.metasketch.file.FileHandlingMenu;
import org.metasketch.logger.Log;

public class DEMOEditor extends Editor {

	FileHandler handler = new FileHandler();

	// IProjectHandler projectHandler = new DEMOProjectHandler();

	IProjectHandler projectHandler = new MultipleProjectHandler();

	FileHandlingMenu fileHandlingMenu = new FileHandlingMenu(this, handler,
			projectHandler);

	JFXPrintTextArea debug = new JFXPrintTextArea();

	// DiagramView diagramView = new DiagramView();

	PerspectiveChooser perspectiveChooser = new PerspectiveChooser(this);

	// IProjectBuilder builder = new DEMOProjectBuilder();

	GenericTools tools = new GenericTools();

	public DEMOEditor() {
		// setup();
		SnapshotManager.setEditor(this);
	}

	public void setup() throws Throwable {
		super.setup();

		Log.setLogger(debug);
		//
		// fileHandlingMenu.setup(this);
		//
		top.setCenter(tools);
		top.setBottom(perspectiveChooser);

		bottom.setCenter(debug.getTextPane());

		// center.setCenter(diagramView);

		// TODO toolbox
		// right.setCenter(diagramView);

		setProject(projectHandler.newProject());

		SnapshotManager.takeSnapshot();
	}

	@Override
	public void resetLayout() {
		// center.setTop(null);

		center.getChildren().clear();
		right.getChildren().clear();
		left.getChildren().clear();
	}

	// public DiagramView getDiagramView() {
	// return diagramView;
	// }

	@Override
	protected void loadProject() {
		// TODO create interface according to project type ????

		perspectiveChooser.setProject(project);

		// DEMOProjectBuilder builder = new DEMOProjectBuilder();
		// builder.buildProject(this, project);
	}

	@Override
	protected void cleanInterface() {
		resetLayout();
		perspectiveChooser.clear();
		// diagramView.clear();
		debug.clean();

	}

}
